import { regExp } from './regExp'

/**
 * @description 密码强度校验，返回强度等级
 * @param {string} val
 * @returns
 */
function getPwdStrength(val) {
  let strengthType = 1

  if (regExp.pwdStrengthStrong.test(val)) {
    strengthType = 3
  } else if (regExp.pwdStrengthHigth.test(val)) {
    strengthType = 2
  } else if (regExp.pwdStrengthLow.test(val)) {
    strengthType = 1
  }

  return strengthType
}

export const formRules = {
  contact: [
    { required: true, trigger: 'blur', message: '请输入联系方式' },
    { pattern: regExp.contact, trigger: 'blur', message: '请输入正确的联系方式' }
  ],
  phone: [
    { required: true, trigger: 'blur', message: '请输入手机号' },
    { pattern: regExp.phone, trigger: 'blur', message: '请输入正确的手机号码' }
  ],
  maxStr: [
    { required: true, trigger: 'blur', message: '请填写内容' },
    { trigger: 'blur', max: 50, message: '最多50个字符' }
  ],
  singleContact: [{ pattern: regExp.contact, trigger: 'blur', message: '请输入正确的联系方式' }],
  singlePhone: [{ pattern: regExp.phone, trigger: 'blur', message: '请输入正确的手机号码' }],
  singleMaxStr: { trigger: 'blur', max: 50, message: '最多50个字符' },
  set: (message = '', trigger = 'blur') => ({
    required: true,
    trigger,
    message
  }),
  getPwdStrength
}
